<template>
  <Spin :spinning="loading" tip="Loading...">
    <div>
      <!-- 索赔扣款信息查询-详情页面 -->
      <BreakSpace label="索赔扣款基本信息" :containerStyle="{ marginBottom: '10px' }" />
      <FormPanel ref="formPanel1" :list="formList" :cols="3" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <BaseDialog :visible.sync="suopeidan" :title="'索赔单号选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <SelectSuopeiDan @close="suopeidanClose" @save="suopeidanSave"></SelectSuopeiDan>
      </BaseDialog>
      <BreakSpace label="维修项目列表" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="weixiuxiangmutable"
        :columns="columns"
        :params="fetchParams"
        :dataSource="dataList"
        :datakey="'items'"
        :onColumnsChange="columns => (this.columns = columns)"
        :onRowSelectChange="selectChange"
        :isSelectColumn="false"
        :onCellChange="changeCells"
        :isPagination = false
        height="auto"
      >
      </FilterTable>
      <div style="margin-bottom: 1rem;"></div>
      <!-- 备件换上件列表 -->
      <BreakSpace label="备件换上件列表" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="peijianhuanshangjiantable"
        :columns="columns1"
        :params="fetchParams"
        :dataSource="dataList1"
        :datakey="'items'"
        :onColumnsChange="columns1 => (this.columns1 = columns1)"
        :onRowSelectChange="selectChange"
        :isSelectColumn="false"
        :onCellChange="changeCells1"
        :isPagination = false
        height="auto"
      >

      </FilterTable>
      <!-- 旧件列表 -->
      <BreakSpace label="旧件列表" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="peijianhuanxiajiantable"
        :columns="columnshuanxiajian"
        :params="fetchParams"
        :dataSource="huanxiajiandataList"
        :datakey="'items'"
        :onColumnsChange="columnshuanxiajian => (this.columnshuanxiajian = columnshuanxiajian)"
        :onRowSelectChange="selectChange"
        :isSelectColumn="false"
        :isPagination = false
        height="auto"
      >
      </FilterTable>
      <!-- 附加项目列表 -->
      <BreakSpace label="附加项目列表" :containerStyle="{ marginBottom: '10px' }" />
      <FilterTable
        ref="fujiaxiangmutable"
        :columns="columnsfujiaxiangmu"
        :params="fetchParams"
        :dataSource="fujiaxiangmudataList"
        :datakey="'items'"
        :onColumnsChange="columnsfujiaxiangmu => (this.columnsfujiaxiangmu = columnsfujiaxiangmu)"
        :onRowSelectChange="selectChange"
        :isSelectColumn="false"
        :onCellChange="changeCells2"
        :isPagination = false
        height="auto"
      >
      </FilterTable>
      <!--申请费用信息  -->
      <!--    <BreakSpace label="申请费用信息" :containerStyle="{ marginBottom: '10px' }" />-->
      <!--    <FormPanel ref="formPanel2" :list="shenqingfeiyongformList" :cols="4" :formType="'add'" labelWidth="110" @formChange="formChangeHandle1" :isSubmitBtn="false" />-->
      <BreakSpace label="外出救援费用" :containerStyle="{ marginBottom: '10px' }" />
      <FormPanel ref="formPanelOutAmount" :list="outAmountformList" :cols="5" :formType="'add'" labelWidth="110" @formChange="formChangeHandleOutAmount" :isSubmitBtn="false" />

      <!--审核费用信息  -->
      <BreakSpace label="审核费用信息" :containerStyle="{ marginBottom: '10px' }" />
      <FormPanel ref="formPanel3" :list="shenhefeiyongformList" :cols="4" :formType="'add'" labelWidth="110" @formChange="formChangeHandle2" :isSubmitBtn="false" />
      <!--扣款信息  -->
      <BreakSpace label="扣款信息" :containerStyle="{ marginBottom: '10px' }" />
      <FormPanel ref="formPanel4" :list="koukuanfeiyongformList" :cols="4" :formType="'add'" labelWidth="110" @formChange="formChangeHandle3" :isSubmitBtn="false" />
      <!--    <LazyLoadTab v-model="activeName" :tabMenus="menus"></LazyLoadTab>-->
      <div style="padding-top: 3rem;"></div>
      <div
        :style="{
        position: 'fixed',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
      >
        <multiuse-button type="primary" @click="back" v-show="editIds.length > 0" :disabled="index == 0">上一单</multiuse-button>
        <multiuse-button type="primary" @click="next" v-show="editIds.length > 0" :disabled="index == editIds.length - 1" >下一单</multiuse-button>
        <multiuse-button type="primary" :click="saveDialog.bind()" :disabled="flag">保 存</multiuse-button>
        <multiuse-button type="primary" :click="submitDialog.bind()" :disabled="flag">确 认</multiuse-button>
        <multiuse-button type="primary" :click="cancelDialog.bind()" :disabled="flag">作 废</multiuse-button>
        <multiuse-button type="primary" @click="closeDialog">关 闭</multiuse-button>
      </div>
    </div>
  </Spin>
</template>
<script>
import { queryRpCmsClaimCb,edit } from '@/api/claim/factory/ClaimDebitsInfoMaintain';
import { isFormEmpty } from '@/utils/index';
import SelectSuopeiDan from './SelectSuopeiDan.vue';
import { copyUpdateData } from '@/utils/index';
import { dictionary } from '@/utils/dictMixin';
import { getRescueList } from '@/api/customerRepair/rescueManagement/rescueOrder';
import { plus } from '@/utils/validate';

export default {
  props: ['rowData', 'editIds'],
  mixins: [dictionary],
  components: {
    SelectSuopeiDan
  },
  data() {
    return {
      index: 0,
      loading: false,
      dataList: [],
      dataList1: [],
      huanxiajiandataList: [],
      fujiaxiangmudataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      flterValue: {}, //参数
      columns: this.creatHeader(),
      columns1: this.creatHeader1(),
      columnshuanxiajian: this.columnshuanxiajian1(),
      columnsfujiaxiangmu: this.columnsfujiaxiangmu1(),
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中服务中心
      formList: this.createFormList(),
      suopeidan: false,
      // shenqingfeiyongformList: this.shenqingfeiyong(),
      outAmountformList: this.outAmountformListFn(),
      shenhefeiyongformList: this.shenhefeiyong(),
      koukuanfeiyongformList: this.koukuanxinxi(),
      saveData: {},
      saveData1:null,
      saveData2:null,
      saveData3:null,
      saveData4:null,
      saveData5:null,
      saveDataOut:null,
      flag:false,
    };
  },
  async created() {
    this.loading = true;
    await this.chuqi();
    if (this.editIds.length) {
      await this.getRpCmsClaimCbs(this.editIds[0].cbId);
    } else {
      await this.getRpCmsClaimCbs(this.rowData.cbId);
    }
    this.loading = false;
  },
  mounted() {
    // this.getRpCmsClaimCb(this.rowData.cbId);

  },
  methods: {
    back() {
      if(this.index != 0){
        this.index --;
        this.getRpCmsClaimCbs(this.editIds[this.index].cbId);
      }
    },
    next() {
      if(this.index != this.editIds.length - 1){
        this.index ++;
      }
      this.getRpCmsClaimCbs(this.editIds[this.index].cbId);
    },
    sumAmount1() {
      let sum = 0;
      let cbOutAmount = 0;
      let cbTravelAmount = 0;
      let partResidue = 0;
      let serviceResidue = 0;
      let cbPartAmount = 0;
      let cbPtManageAmount = 0;
      let cbOtherAmount = 0;

      this.$refs.weixiuxiangmutable.$refs.pageTable.list.map(x => {
        sum += Number(x.deductionAmount);
      });
      this.$refs.fujiaxiangmutable.$refs.pageTable.list.map(x => {
        sum += Number(x.deductionAmount);
      });
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.list.map(x => {
        sum += Number(x.deductionAmount);
      });

      cbPartAmount=this.koukuanfeiyongformList.find(x => x.fieldName == 'cbPartAmount').initialValue;

      cbOutAmount=this.koukuanfeiyongformList.find(x => x.fieldName == 'cbOutAmount').initialValue;
      if(cbOutAmount>0){
        sum += Number(cbOutAmount);
      }
      cbTravelAmount=this.koukuanfeiyongformList.find(x => x.fieldName == 'cbTravelAmount').initialValue;

      if(cbTravelAmount>0){
        sum += Number(cbTravelAmount);
      }
      cbPtManageAmount=this.koukuanfeiyongformList.find(x => x.fieldName == 'cbPtManageAmount').initialValue;

      if(cbPtManageAmount>0){
        sum += Number(cbPtManageAmount);
      }
      cbOtherAmount=this.koukuanfeiyongformList.find(x => x.fieldName == 'cbOtherAmount').initialValue;

      if(cbOtherAmount>0){
        sum += Number(cbOtherAmount);
      }
      // 材料费剩余金额=备件扣款金额+物流费用
      // 7。28 update索赔抵扣单中物流费用扣款统计在服务费扣款中
      // partResidue=Number(cbPartAmount)+Number(cbTravelAmount);
      partResidue=Number(cbPartAmount);
      // 服务费剩余金额=总扣款金额-材料费剩余金额
      serviceResidue=sum-Number(partResidue);
      let realVal = parseFloat(sum).toFixed(2);
      let realPartResidueVal = partResidue.toFixed(2);
      let realServiceResidueVal = serviceResidue.toFixed(2);
      this.koukuanfeiyongformList.map(x => {
        if('partResidue' == x.fieldName) {
          x.initialValue = realPartResidueVal;
        }
        if('serviceResidue' == x.fieldName) {
          x.initialValue = realServiceResidueVal;
        }
        if('cbSumAmount' == x.fieldName) {
          x.initialValue = realVal;
        }
      });
    },
    async changeCells(keys, obj) {
      let sumweixiufeiyong = 0;
      this.$refs.weixiuxiangmutable.$refs.pageTable.list.map(x => {
        sumweixiufeiyong += Number(x.deductionAmount);
      });
      this.koukuanfeiyongformList.map(x => {
        if ('cbLabourAmount' == x.fieldName) {
          x.initialValue = Number(sumweixiufeiyong).toFixed(2);
        }
      });
      this.sumAmount1();
    },
    async changeCells1(keys, obj) {
      let sumweixiufeiyong = 0;
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.list.map(x => {
        sumweixiufeiyong += Number(x.deductionAmount);
      });
      this.koukuanfeiyongformList.map(x => {
        if ('cbPartAmount' == x.fieldName) {
          x.initialValue = Number(sumweixiufeiyong).toFixed(2);
        }
      });
      this.sumAmount1();
    },
    async changeCells2(keys, obj) {
      let sumweixiufeiyong = 0;
      this.$refs.fujiaxiangmutable.$refs.pageTable.list.map(x => {
        sumweixiufeiyong += Number(x.deductionAmount);
      });
      this.koukuanfeiyongformList.map(x => {
        if ('cbAddAmount' == x.fieldName) {
          x.initialValue = Number(sumweixiufeiyong).toFixed(2);
        }
      });
      this.sumAmount1();
    },
    async chuqi() {
      // //扣款单状态
      // const res = await getPartType({ type: 5591 });
      // if (res.resultCode == 200) {
      //   this.formList.find(x => x.fieldName == 'cbStatus').itemList = res.data.map(y => ({ text: y.codeCnDesc, value: y.codeId }));
      // }

    },
    async getRpCmsClaimCbs(cbId) {
      let res = await queryRpCmsClaimCb(cbId);
      let data = res.data;
      this.claimId = data.claimId;
      this.ownerCode = data.ownerCode;
      this.ownerParCode = data.ownerParCode;
      this.cbId = data.cbId;
      if(data.cbStatus==55911001 ){
        this.flag=true;
      }else {
        this.flag=false;
      }
      //为4个form赋值
      for (let i in data) {
        this.formList.map(y => {
          if (i == y.fieldName) {
            y.initialValue = data[i];
          }
        });
      }
      for (let i in data.claimDTO) {
        // this.shenqingfeiyongformList.map(y => {
        //   if (i == y.fieldName) {
        //     y.initialValue = data.claimDTO[i];
        //   }
        // });
        this.shenhefeiyongformList.map(y => {
          if (i == y.fieldName) {
            data.claimDTO[i]=data.claimDTO[i]==null?0:data.claimDTO[i];
            y.initialValue = parseFloat(data.claimDTO[i]).toFixed(2);
          }
        });
        this.koukuanfeiyongformList.map(y => {
          if (i == y.fieldName) {
            data.claimDTO[i]=data.claimDTO[i]==null?0:data.claimDTO[i];
            y.initialValue = parseFloat(data.claimDTO[i]).toFixed(2);
          }
        });
      }
      //为table赋值
      if (200 == res.resultCode) {
        let data = res.data;
        if (isFormEmpty(data)) {
          data = {};
        }
        //维修项目
        let records = data.labourList;
        if (isFormEmpty(records)) {
          records = [];
        }else{
          records.forEach(x => {
            x.cmsClaimPrice= parseFloat(x.cmsClaimPrice).toFixed(2);
            x.cmsClaimAmount= parseFloat(x.cmsClaimAmount).toFixed(2);
            x.deductionAmount= parseFloat(x.deductionAmount).toFixed(2);
          });
        }
        this.$refs.weixiuxiangmutable.$refs.pageTable.EXECUTE_DELETE(this.$refs.weixiuxiangmutable.$refs.pageTable.list);
        this.$refs.weixiuxiangmutable.$refs.pageTable.EXECUTE_INSERT(records);
        //附加项目
        let records1 = data.addList;
        if (isFormEmpty(records1)) {
          records1 = [];
        }else{
          records1.forEach(x => {
            x.addAmount= parseFloat(x.addAmount).toFixed(2);
            x.deductionAmount= parseFloat(x.deductionAmount).toFixed(2);
          });
        }
        this.$refs.fujiaxiangmutable.$refs.pageTable.EXECUTE_DELETE(this.$refs.fujiaxiangmutable.$refs.pageTable.list);
        this.$refs.fujiaxiangmutable.$refs.pageTable.EXECUTE_INSERT(records1);
      }
      //故障件
      let records2 = data.partList;
      if (isFormEmpty(records2)) {
        records2 = [];
      }else{
        records2.forEach(x => {
          x.cmsClaimPrice= parseFloat(x.cmsClaimPrice).toFixed(2);
          x.cmsClaimAmount= parseFloat(x.cmsClaimAmount).toFixed(2);
        });
      }
      this.$refs.peijianhuanxiajiantable.$refs.pageTable.EXECUTE_DELETE(this.$refs.peijianhuanxiajiantable.$refs.pageTable.list);
      this.$refs.peijianhuanxiajiantable.$refs.pageTable.EXECUTE_INSERT(records2);
      //备件
      let records3 = data.partRpList;
      if (isFormEmpty(records3)) {
        records3 = [];
      }else{
        records3.forEach(x => {
          x.cmsClaimPrice= parseFloat(x.cmsClaimPrice).toFixed(2);
          x.cmsClaimAmount= parseFloat(x.cmsClaimAmount).toFixed(2);
          x.deductionAmount= parseFloat(x.deductionAmount).toFixed(2);
        });
      }
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.EXECUTE_DELETE(this.$refs.peijianhuanshangjiantable.$refs.pageTable.list);
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.EXECUTE_INSERT(records3);
      if(null!=data.outId){
        let res = await getRescueList({outId: data.outId,current: 1,currentPage: 1,page: 1,pageNum: 1,pageSize: 10,size: 10}); // 救援单

        let records = res.data.records[0];
        for (let i in records) {
          this.outAmountformList.map(y => {
            if (i == y.fieldName) {
              if(y.fieldName!='rewardType'){
                records[i]=records[i]==null?0:records[i];
                y.initialValue = parseFloat(records[i]).toFixed(2);
              }else{
                y.initialValue = records[i];
              }
            }
          });
        }
        if(records!=null){
          this.shenhefeiyongformList.find(x => x.fieldName == 'helpAmount').initialValue =parseFloat(records.allAmount).toFixed(2);
        }
      }
      this.changeCells();
      this.changeCells1();
      this.changeCells2();
      this.newVar = data;
    },
    async submitDialog(){
      this.$refs.formPanel1.SUBMIT_FORM();
      // this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.$refs.formPanel4.SUBMIT_FORM();
      let arr = [];
      this.$refs.fujiaxiangmutable.$refs.pageTable.list.map(x => {
        arr.push(x);
      });
      console.log(arr);

      let arr1 = [];
      this.$refs.peijianhuanxiajiantable.$refs.pageTable.list.map(x => {
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.list.map(x => {
        arr2.push(x);
      });
      console.log(arr2);

      let arr3 = [];
      this.$refs.weixiuxiangmutable.$refs.pageTable.list.map(x => {
        arr3.push(x);
      });
      console.log(arr3);

      //维修项目
      this.saveData.labourList = arr3;
      //换上件
      this.saveData.partRpList = arr2;
      //换下件
      this.saveData.partList = arr1;
      //附加项目
      this.saveData.addList = arr;

      this.saveData = Object.assign(this.saveData, this.saveData1);

      this.saveData = Object.assign(this.saveData, this.saveData2);

      this.saveData = Object.assign(this.saveData, this.saveDataOut);

      this.saveData = Object.assign(this.saveData, this.saveData3);

      this.saveData = Object.assign(this.saveData, this.saveData4);

      //追加子表的主键
      if(this.claimId!=null){
        this.saveData.claimId = this.claimId;
      }else{
        this.saveData.claimId = this.rowData.claimId;
      }
      if(this.rowData.cbId){
        this.saveData.cbId = this.rowData.cbId;
      }else{
        this.saveData.cbId = this.cbId;
      }
      this.saveData.cbStatus =55021002;
      this.saveData.finalSumAmount =parseFloat(this.saveData.claimSumAmount - this.saveData.cbSumAmount).toFixed(2);
      this.newVar = copyUpdateData(this.newVar,this.saveData);

      if (this.saveData !== null) {
        this.loading = true;
        let res = await edit(this.newVar);

        if (res.resultCode === 200) {
          if(this.editIds.length){
            this.loading = false;
            this.editIds[this.index].status = 1;
            this.next();
          } else {
            this.loading = false;
            this.$emit('save');
          }
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          this.closeDialog();
        }

      }else {
        this.loading = false;
        return this.$notify.warning({ title: '提示信息', message: '有未校验通过的信息' });
      }


    },
    async saveDialog() {
      this.$refs.formPanel1.SUBMIT_FORM();
      // this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.$refs.formPanel4.SUBMIT_FORM();
      let arr = [];
      this.$refs.fujiaxiangmutable.$refs.pageTable.list.map(x => {
        arr.push(x);
      });
      console.log(arr);

      let arr1 = [];
      this.$refs.peijianhuanxiajiantable.$refs.pageTable.list.map(x => {
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.list.map(x => {
        arr2.push(x);
      });
      console.log(arr2);

      let arr3 = [];
      this.$refs.weixiuxiangmutable.$refs.pageTable.list.map(x => {
        arr3.push(x);
      });
      console.log(arr3);

      //维修项目
      this.saveData.labourList = arr3;
      //换上件
      this.saveData.partRpList = arr2;
      //换下件
      this.saveData.partList = arr1;
      //附加项目
      this.saveData.addList = arr;

      this.saveData = Object.assign(this.saveData, this.saveData1);

      this.saveData = Object.assign(this.saveData, this.saveData2);

      this.saveData = Object.assign(this.saveData, this.saveDataOut);

      this.saveData = Object.assign(this.saveData, this.saveData3);

      this.saveData = Object.assign(this.saveData, this.saveData4);

      //追加子表的主键
      if(this.claimId!=null){
        this.saveData.claimId = this.claimId;
      }else{
        this.saveData.claimId = this.rowData.claimId;
      }
      if(this.rowData.cbId){
        this.saveData.cbId = this.rowData.cbId;
      }else{
        this.saveData.cbId = this.cbId;
      }
      this.saveData.finalSumAmount =parseFloat(this.saveData.claimSumAmount - this.saveData.cbSumAmount).toFixed(2);

      this.newVar = copyUpdateData(this.newVar,this.saveData);
      this.saveData.cbStatus=55021001;//已保存状态
      if (this.saveData !== null) {
        this.loading = true;
        let res = await edit(this.newVar);
        if (res.resultCode === 200) {
          if(this.editIds.length){
            this.loading = false;
            this.editIds[this.index].status = 1;
            this.next();
          } else {
            this.loading = false;
            this.$emit('save');
          }
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          this.closeDialog();
        }

      }else {
        this.loading = false;
        return this.$notify.warning({ title: '提示信息', message: '有未校验通过的信息' });
      }


    },
    async cancelDialog() {
      this.$refs.formPanel1.SUBMIT_FORM();
      // this.$refs.formPanel2.SUBMIT_FORM();
      this.$refs.formPanel3.SUBMIT_FORM();
      this.$refs.formPanel4.SUBMIT_FORM();
      let arr = [];
      this.$refs.fujiaxiangmutable.$refs.pageTable.list.map(x => {
        arr.push(x);
      });
      console.log(arr);

      let arr1 = [];
      this.$refs.peijianhuanxiajiantable.$refs.pageTable.list.map(x => {
        arr1.push(x);
      });
      console.log(arr1);

      let arr2 = [];
      this.$refs.peijianhuanshangjiantable.$refs.pageTable.list.map(x => {
        arr2.push(x);
      });
      console.log(arr2);

      let arr3 = [];
      this.$refs.weixiuxiangmutable.$refs.pageTable.list.map(x => {
        arr3.push(x);
      });
      console.log(arr3);

      //维修项目
      this.saveData.labourList = arr3;
      //换上件
      this.saveData.partRpList = arr2;
      //换下件
      this.saveData.partList = arr1;
      //附加项目
      this.saveData.addList = arr;

      this.saveData = Object.assign(this.saveData, this.saveData1);

      this.saveData = Object.assign(this.saveData, this.saveData2);

      this.saveData = Object.assign(this.saveData, this.saveDataOut);

      this.saveData = Object.assign(this.saveData, this.saveData3);

      this.saveData = Object.assign(this.saveData, this.saveData4);

      //追加子表的主键
      if(this.claimId!=null){
        this.saveData.claimId = this.claimId;
      }else{
        this.saveData.claimId = this.rowData.claimId;
      }
      if(this.rowData.cbId){
        this.saveData.cbId = this.rowData.cbId;
      }else{
        this.saveData.cbId = this.cbId;
      }
      this.saveData.cbStatus =55021003;
      this.saveData.finalSumAmount =parseFloat(this.saveData.claimSumAmount - this.saveData.cbSumAmount).toFixed(2);

      this.newVar = copyUpdateData(this.newVar,this.saveData);

      if (this.saveData !== null) {
        this.loading = true;
        let res = await edit(this.newVar);
        if (res.resultCode === 200) {
          if(this.editIds.length){
            this.loading = false;
            this.editIds[this.index].status = 1;
            this.next();
          } else {
            this.loading = false;
            this.$emit('save');
          }
        } else {
          this.loading = false;
          this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          this.closeDialog();
        }

      }else {
        this.loading = false;
        return this.$notify.warning({ title: '提示信息', message: '有未校验通过的信息' });
      }


    },
    formChangeHandle(val) {
      console.log(val);
      this.saveData1 = val;
    },
    formChangeHandle1(val) {
      console.log(val);
      this.saveData2 = val;
    },
    formChangeHandleOutAmount(val) {
      console.log(val);
      this.saveDataOut = val;
    },
    formChangeHandle2(val) {
      console.log(val);
      this.saveData3 = val;
    },
    formChangeHandle3(val) {
      console.log(val);
      this.saveData4 = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val);
      console.log(val);
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    // //保存
    // saveDialog() {
    //   this.$refs.formPanel1.SUBMIT_FORM();
    //   if (this.saveData) {
    //     this.$emit('save', this.selectedRows);
    //   }
    // },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    },
    selectRono() {
      this.suopeidan = true;
    },
    suopeidanClose() {
      this.suopeidan = false;
    },
    suopeidanSave(obj) {
      this.formList.find(x => x.fieldName == 'ownerCode').initialValue = obj[0].ownerCode;
      this.formList.find(x => x.fieldName == 'dealerName').initialValue = obj[0].dealerName;
      this.formList.find(x => x.fieldName == 'claimType').initialValue = obj[0].cmsClaimType;
      this.formList.find(x => x.fieldName == 'claimNo').initialValue = obj[0].claimNo;
      this.formList.find(x => x.fieldName == 'finalSumAmount').initialValue = obj[0].finalSumAmount;
      this.claimId = obj[0].claimId;
      this.getRpCmsClaimCb(this.claimId);
      this.suopeidan = false;
    },
    add() {},
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '索赔扣款单号',
          fieldName: 'cbNo',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务中心代码',
          fieldName: 'dealerCode',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务中心名称',
          fieldName: 'dealerName',
          initialValue: '',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '扣款单状态',
          fieldName: 'cbStatus',
          initialValue: '',
          itemList: this.createDictList('5502'),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '索赔单号',
          fieldName: 'claimNo',
          initialValue: '',
          placeholder: '请输入标题名称...',
          rules: [{ required: true, message: '请输入标题名称', trigger: 'blur' }],
          readonly: true,
          disabled: true,
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.selectRono()} />
              </div>
            );
          }
        },
        {
          type: 'INPUT',
          label: '扣款原因',
          fieldName: 'cbReason',
          rules: [{ required: true, message: '请输入扣款原因', trigger: 'change' }],

        },
        {
          type: 'SELECT',
          label: '索赔类型',
          fieldName: 'claimType',
          itemList:this.createDictList('5510',[]),
          disabled: true
        },
        {
          type: 'INPUT',
          label: '现结算金额',
          fieldName: 'finalSumAmount',
          initialValue: '',
          hidden:true,
          disabled: true
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remarks',
          selfCols:3,
          placeholder: '请输入备注...',
          rules: [{ required: false, message: '请输入', trigger: 'blur' }]
        }
      ];
    },

    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '维修项目代码', dataIndex: 'labourCode', sorter: true },
        { title: '维修项目名称', dataIndex: 'labourName', sorter: true },
        { title: '维修类型', dataIndex: 'repairTypeName', sorter: true },
        { title: '标准工时', dataIndex: 'labourHours', sorter: true },
        { title: '索赔工时单价', dataIndex: 'cmsClaimPrice', sorter: true },
        { title: '索赔金额', dataIndex: 'cmsClaimAmount', sorter: true },
        // { title: '审核金额', dataIndex: 'checkAmount', sorter: true},
        {
          title: '扣款金额',
          dataIndex: 'deductionAmount',
          editable: true,
          editRequired: true,
          filterType: 'input',
          editType: 'number',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          editValidator:(val, row, callback) => {
            if(row.deductionAmount>0){
              if (parseFloat(row.deductionAmount) > parseFloat(row.cmsClaimAmount)) {
                this.$notify.error({ title: '提示信息', message: '已超过索赔金额(' + row.cmsClaimAmount + ')' || '操作失败!' });
                row.deductionAmount = row.cmsClaimAmount
                this.changeCells();
              }
            }else{
              this.$notify.error({ title: '提示信息', message: '扣款金额不能为负数' || '操作失败!' });
              row.deductionAmount = row.cmsClaimAmount
              this.changeCells();
            }

          }
        }
      ];
    },
    //table表头和数据源
    creatHeader1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '备件代码', dataIndex: 'partCode', sorter: true },
        { title: '备件名称', dataIndex: 'partName', sorter: true },
        { title: '单位', dataIndex: 'partUnit', sorter: true },
        { title: '数量', dataIndex: 'partCount', sorter: true },
        { title: '索赔单价', dataIndex: 'cmsClaimPrice', sorter: true },
        { title: '索赔总价', dataIndex: 'cmsClaimAmount', sorter: true },
        // { title: '调整后金额', dataIndex: 'checkAmount', sorter: true},
        {
          title: '扣款金额',
          dataIndex: 'deductionAmount',
          editable: true,
          editRequired: true,
          filterType: 'input',
          editType: 'number',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          editValidator:(val, row, callback) => {
            if(row.deductionAmount>0){
              if (parseFloat(row.deductionAmount) > parseFloat(row.cmsClaimAmount)) {
                this.$notify.error({ title: '提示信息', message: '已超过索赔总价(' + row.cmsClaimAmount + ')' || '操作失败!' });
                row.deductionAmount = row.cmsClaimAmount
                this.changeCells1();
              }
            }else{
              this.$notify.error({ title: '提示信息', message: '扣款金额不能为负数' || '操作失败!' });
              row.deductionAmount = row.cmsClaimAmount
              this.changeCells1();
            }

          }
        },
      ];
    },
    //换下件
    columnshuanxiajian1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '备件代码', dataIndex: 'partCode', sorter: true },
        { title: '备件名称', dataIndex: 'partName', sorter: true },
        { title: '变更前备件代码', dataIndex: 'partCodeBefore', sorter: true },
        { title: '变更前备件名称', dataIndex: 'partNameBefore', sorter: true },
        { title: '单位', dataIndex: 'partUnit', sorter: true },
        { title: '数量', dataIndex: 'partCount', sorter: true },
        { title: '单价', dataIndex: 'cmsClaimPrice', sorter: true },
        { title: '金额', dataIndex: 'cmsClaimAmount', sorter: true },
        { title: '备件回运类型', dataIndex: 'returnType', sorter: true,dictItems:this.createDictList('5585'), },
        { title: '采购渠道代码', dataIndex: 'channelCode', sorter: true  },
      ];
    },
    //附加项目
    columnsfujiaxiangmu1() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '附加项目代码', dataIndex: 'addCode', sorter: true },
        { title: '附加项目名称', dataIndex: 'addName', sorter: true },
        { title: '索赔金额', dataIndex: 'addAmount', sorter: true },
        // { title: '审核金额', dataIndex: 'checkAmount', sorter: true },
        {
          title: '扣款金额',
          dataIndex: 'deductionAmount',
          editable: true,
          editRequired: true,
          filterType: 'input',
          editType: 'number',
          rules: [{ required: true, message: '请输入', trigger: 'blur' }],
          editValidator:(val, row, callback) => {
            if(row.deductionAmount>=0){
              if (parseFloat(row.deductionAmount) > parseFloat(row.addAmount)) {
                this.$notify.error({ title: '提示信息', message: '已超过索赔金额(' + row.addAmount + ')' || '操作失败!' });
                row.deductionAmount = row.addAmount
                this.changeCells2();
              }
            }else{
              this.$notify.error({ title: '提示信息', message: '扣款金额不能为负数' || '操作失败!' });
              row.deductionAmount = row.addAmount
              this.changeCells2();
            }

          }
        },
        { title: '备注', dataIndex: 'addRemark', sorter: true }
      ];
    },
    //外出救援费用
    outAmountformListFn() {
      return [
        {
          type: 'INPUT',
          label: '燃油补贴',
          fieldName: 'fuelSubsidy',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '人员补贴',
          fieldName: 'prSubsidy',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '餐补',
          fieldName: 'foodSubsidy',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '住宿补贴',
          fieldName: 'staySubsidy',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '车船费',
          fieldName: 'crossAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '拖车费',
          fieldName: 'trailerAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '其他费用',
          fieldName: 'otherAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'SELECT',
          label: '激励类型',
          fieldName: 'rewardType',
          initialValue: '',
          itemList: this.createDictList('5537',[]),
          disabled:true,
          hidden:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '奖励金额',
          fieldName: 'reward',
          initialValue: '',
          disabled:true,
          hidden:true,
          readonly: true // 只读
        }
      ];
    },
    //审核费用信息
    shenhefeiyong() {
      return [
        {
          type: 'INPUT',
          label: '合计费用',
          fieldName: 'claimSumAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '工时费用',
          fieldName: 'claimLabourAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '备件费用',
          fieldName: 'claimPartAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '备件管理费用',
          fieldName: 'partManageAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '附加项目费用',
          fieldName: 'claimAddAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '外出费用',
          fieldName: 'helpAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: 'PDI费用',
          fieldName: 'priceAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '扣款金额',
          fieldName: 'outCbAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        }
      ];
    },//扣款信息
    koukuanxinxi() {
      return [
        {
          type: 'INPUT',
          label: '合计扣款',
          fieldName: 'cbSumAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '工时扣款',
          fieldName: 'cbLabourAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '备件扣款',
          fieldName: 'cbPartAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '附加项目扣款',
          fieldName: 'cbAddAmount',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '外出费用扣款',
          fieldName: 'cbOutAmount',
          initialValue: '0.00',
          rules: [
            { required: false, validator: plus, trigger: 'blur' },
          ],
          change: val => {
            this.sumAmount1();
          }
        },
        {
          type: 'INPUT',
          label: '物流费用扣款',
          fieldName: 'cbTravelAmount',
          initialValue: '0.00',
          rules: [
            { required: false, validator: plus, trigger: 'blur' },
          ],
          change: val => {
            this.sumAmount1();
          }
        },
        {
          type: 'INPUT',
          label: '备件管理费用扣款',
          fieldName: 'cbPtManageAmount',
          initialValue: '0.00',
          rules: [
            { required: false, validator: plus, trigger: 'blur' },
          ],
          change: val => {
            this.sumAmount1();
          }
        },
        {
          type: 'INPUT',
          label: '其他费用扣款',
          fieldName: 'cbOtherAmount',
          initialValue: '0.00',
          rules: [
            { required: false, validator: plus, trigger: 'blur' },
          ],
          change: val => {
            this.sumAmount1();
          }
        },
        {
          type: 'INPUT',
          label: '材料剩余金额',
          fieldName: 'partResidue',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
        {
          type: 'INPUT',
          label: '服务剩余金额',
          fieldName: 'serviceResidue',
          initialValue: '0.00',
          disabled:true,
          readonly: true // 只读
        },
      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
